﻿
function LOG(str) {
  dump("*** " + str + "\n");
}

var EXPORTED_SYMBOLS = ["PlacesUtils"];

var Ci = Components.interfaces;
var Cc = Components.classes;
var Cr = Components.results;
var Cu = Components.utils;

Cu.import("resource://gre/modules/XPCOMUtils.jsm");

function toJSONString(aObj) {
    var JSON = Cc["@mozilla.org/dom/json;1"].createInstance(Ci.nsIJSON);
    return JSON.encode(aObj);
}

/**
* Îòïðàâêà ñòðóêòóðû çàêëàäîê íà ñåðâåð
*/
function doPost() {
	// Some GUI changes
	// set progressbar visible
	var bar = document.getElementById("sharebookmarks-progressBar");
	bar.setAttribute("style", "visibility: visible;");
	// set textfields inactive
	var textFieldsGroupBox = document.getElementById("textFieldsGroupBox");
	textFieldsGroupBox.setAttribute("style", "z-index: -10;"); //don't let input anything... doesn't work =(
	textFieldsGroupBox.setAttribute("style", "opacity: 0.3;");
	
	// TODO: ckeck of existing data inside textfields!!!
	
	// Get JSON bookmarks structure
	var dateObj = new Date();
	var date = dateObj.toLocaleFormat("%d-%m-%Y");
LOG(date);
	var historyService = Components.classes["@mozilla.org/browser/nav-history-service;1"]
								   .getService(Components.interfaces.nsINavHistoryService);
	var historyFolder = bookmarksService.toolbarFolder;
	var options = historyService.getNewQueryOptions();
	var query = historyService.getNewQuery();

	//query.setFolders([PlacesUtils.placesRootId], 1);
	
	var bookmarksService = Components.classes["@mozilla.org/browser/nav-bookmarks-service;1"]
									 .getService(Components.interfaces.nsINavBookmarksService);
	var toolbarFolder = bookmarksService.toolbarFolder;
	query.setFolders([toolbarFolder], 1);
	var result = historyService.executeQuery(query, options);

	var rootNode = result.root;
	rootNode.containerOpen = true;
	// iterate over the immediate children of this folder and dump to console
	for (var i = 0; i < rootNode.childCount; i ++) {
		var node = rootNode.getChild(i);
		dump("Child: " + node.title + "\n");
	}
	// close a container after using it!
	rootNode.containerOpen = false;

	
		
		
}

/**
* // TODO: refactor comment
* 
*/
function onCancelPost() {
	
	return true;
}